﻿using QYmall.Core.Common.Emum;
using QYmall.Core.Common.Extensions;
using QYmall.Core.Common.Helper;
using QYmall.Core.DBFactory.Database;
using QYmall.Core.IServices;
using QYmall.Core.Model.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace QYmall.Core.Services
{
    /// <summary>
    /// 广告内容接口实现
    /// </summary>
    public class AdvertBannerService : BaseService, IAdvertBannerService
    {
        public AdvertBannerService(IDbContextFactory contentFactory) : base(contentFactory) { }

        /// <summary>
        /// 查询分页列表
        /// </summary>
        public async Task<PaginationList<AdvertBanner>> QueryPageAsync(int pageSize, int pageIndex, Expression<Func<AdvertBanner, bool>> funcWhere,
            string orderBy, WriteRoRead writeAndRead = WriteRoRead.Read)
        {
            _context = _contextFactory.CreateContext(writeAndRead);//连接数据库
            var result = _context.Set<AdvertBanner>().Include(x => x.Advert)
                .Where(funcWhere).OrderByBatch(orderBy);//调用Linq扩展类排序
            return await PaginationList<AdvertBanner>.CreateAsync(pageIndex, pageSize, result);
        }

    }
}
